using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using BA.DAL;

namespace BlazeApps.Library.Form
{
    public class FormList : Base
    {
        private BA.DAL.DBUtility DAL = new BA.DAL.DBUtility();
        private Procedures Procs = new Procedures();

        public DataTable GetForms()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataTable(Procs.ListForms.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetAnswers()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataTable(Procs.ListAnswers.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetAnswers(Guid FormID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormID", FormID);

            return DAL.GetDataTable(Procs.ListAnswersByFormID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetAnswers(Guid FormQuestionID, Guid FormResponseID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormQuestionID", FormQuestionID);
            DAL.AddParameter("@FormResponseID", FormResponseID);

            return DAL.GetDataTable(Procs.GetAnswerByQuestionIDAndResponseID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetAnswersForRows(Guid FormQuestionID, Guid FormResponseID, Guid FormRowID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormResponseID", FormResponseID);
            DAL.AddParameter("@FormQuestionID", FormQuestionID);
            DAL.AddParameter("@FormRowID", FormRowID);

            return DAL.GetDataTable(Procs.GetFormAnswerRowColumnByQuestionIDAndRowIDAndResponseID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetAnswersForRowsColumns(Guid FormQuestionID, Guid FormResponseID, Guid FormRowID, Guid FormColumnID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormResponseID", FormResponseID);
            DAL.AddParameter("@FormQuestionID", FormQuestionID);
            DAL.AddParameter("@FormRowID", FormRowID);
			DAL.AddParameter("@FormColumnID", FormColumnID);

            return DAL.GetDataTable(Procs.GetFormAnswerRowColumnByQuestionIDAndRowIDAndColumnIDAndResponseID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetTextAnswers(Guid FormQuestionID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormQuestionID", FormQuestionID);

            return DAL.GetDataTable(Procs.ListAnswerTextResults.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetMatrixSingleAnswerResults(Guid FormQuestionID, Guid FormRowID, Guid FormColumnID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormQuestionID", FormQuestionID);
            DAL.AddParameter("@FormRowID", FormRowID);
            DAL.AddParameter("@FormColumnID", FormColumnID);

            return DAL.GetDataTable(Procs.ListFormMatrixSingleAnswerResults.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetMatrixMultipleAnswerResults(Guid FormQuestionID, Guid FormRowID, Guid FormColumnID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormQuestionID", FormQuestionID);
            DAL.AddParameter("@FormRowID", FormRowID);
            DAL.AddParameter("@FormColumnID", FormColumnID);

            return DAL.GetDataTable(Procs.ListFormMatrixMultipleAnswerResults.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetQuestions()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataTable(Procs.ListFormQuestions.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetQuestions(Guid FormID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormID", FormID);

            return DAL.GetDataTable(Procs.ListFormQuestionsByFormID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetQuestionColumns(Guid QuestionID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormQuestionID", QuestionID);

            return DAL.GetDataTable(Procs.ListFormQuestionColumnsByQuestionID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetQuestionRows(Guid QuestionID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormQuestionID", QuestionID);

            return DAL.GetDataTable(Procs.ListFormQuestionRowsByQuestionID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetControls(Guid FormID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormID", FormID);

            return DAL.GetDataTable(Procs.ListControlsByFormID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetControlList()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataTable(Procs.ListControls.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetResponses(Guid FormID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@FormID", FormID);

            return DAL.GetDataTable(Procs.ListFormResponsesByFormID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetResponses()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataTable(Procs.ListFormResponses.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }
    }
}
